<!--
 * @Author: your name
 * @Date: 2022-04-09 14:43:25
 * @LastEditTime: 2022-04-09 14:51:27
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \geyao\geyao\面试题之找出字符串220409.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>找出字符串</title>
</head>
<body>
  <script>
    //寻找并截取到需要的值 substring第二个参数是截取字符串最终的下标 （截取2个位置之间的字符串,‘含头不含尾’）
    var geyao="woshigeyaofangfanggeyao"
    var search="geyao"
    var start=geyao.indexOf(search)
    var result=geyao.substring(start, start+search.length)
    console.log(result,"result")
  </script>
</body>
</html>